package com.uobgroup.ews.uam.core.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.uobgroup.ews.uam.core.dao.ReferenceTypeDao;
import com.uobgroup.ews.uam.core.domain.ReferenceType;
import com.uobgroup.ews.uam.core.enums.ScopeType;

@Service
@Transactional
public class ReferenceTypeServiceImpl implements ReferenceTypeService {

   @Autowired
   private ReferenceTypeDao referenceTypeDao;

   @Override
   public ReferenceType findReferenceTypeThatHasNameAndNotHasId(String name, Long id) {
      return referenceTypeDao.findReferenceTypeThatHasNameAndNotHasId(name, id);
   }

   @Override
   public ReferenceType findReferenceTypeThatHasCodeAndNotHasId(String code, Long id) {
      return referenceTypeDao.findReferenceTypeThatHasCodeAndNotHasId(code, id);
   }
   
   @Override
   public ReferenceType findReferenceTypeByCodeAndSecurityScope(String code) {
      return referenceTypeDao.findReferenceTypeByCodeAndScope(code, ScopeType.SECURITY);
   }

   @Override
   public ReferenceType findReferenceTypeByCodeAndApplicationScope(String code) {
      return referenceTypeDao.findReferenceTypeByCodeAndScope(code, ScopeType.APPLICATION);
   }

   @Override
   public ReferenceType findReferenceTypeByNameAndSecurityScope(String name) {
      return referenceTypeDao.findReferenceTypeByNameAndScope(name, ScopeType.SECURITY);
   }

   @Override
   public ReferenceType findReferenceTypeByNameAndApplicationScope(String name) {
      return referenceTypeDao.findReferenceTypeByNameAndScope(name, ScopeType.APPLICATION);
   }

   @Override
   public long countReferenceTypesByApplicationScope() {
      return referenceTypeDao.countReferenceTypesByScope(ScopeType.APPLICATION);
   }

   @Override
   public long countReferenceTypesBySecurityScope() {
      return referenceTypeDao.countReferenceTypesByScope(ScopeType.SECURITY);
   }

   @Override
   public List<ReferenceType> findReferenceTypesBySecurityScope() {
      return referenceTypeDao.findReferenceTypesByScope(ScopeType.SECURITY);
   }

   @Override
   public List<ReferenceType> findReferenceTypesByApplicationScope() {
      return referenceTypeDao.findReferenceTypesByScope(ScopeType.APPLICATION);
   }

   @Override
   public List<ReferenceType> findReferenceTypesBySecurityScope(int firstResult, int maxResults) {
      return referenceTypeDao.findReferenceTypesByScope(ScopeType.SECURITY, firstResult, maxResults);
   }

   @Override
   public List<ReferenceType> findReferenceTypesByApplicationScope(int firstResult, int maxResults) {
      return referenceTypeDao.findReferenceTypesByScope(ScopeType.APPLICATION, firstResult, maxResults);
   }

   @Override
   public void deleteReferenceType(ReferenceType referenceType) {
      referenceTypeDao.delete(referenceType);
   }

   @Override
   public void saveReferenceType(ReferenceType referenceType) {
      referenceTypeDao.save(referenceType);
   }

   @Override
   public ReferenceType updateReferenceType(ReferenceType referenceType) {
      return referenceTypeDao.update(referenceType);
   }

   @Override
   public ReferenceType findReferenceType(Long id) {
      return referenceTypeDao.findOne(id);
   }

   @Override
   public ReferenceType findReferenceTypeByIdAndSecurityScope(Long id) {
      return referenceTypeDao.findReferenceTypeByIdAndScope(id, ScopeType.SECURITY);
   }

   @Override
   public ReferenceType findReferenceTypeByIdAndApplicationScope(Long id) {
      return referenceTypeDao.findReferenceTypeByIdAndScope(id, ScopeType.APPLICATION);
   }

   @Override
   public ReferenceType findReferenceTypeByName(String name) {
      return referenceTypeDao.findReferenceTypeByName(name);
   }

   @Override
   public ReferenceType findReferenceTypeByCode(String code) {
      return referenceTypeDao.findReferenceTypeByCode(code);
   }
}
